// 初始化mutations 数据，是store的出口

// ———————————— VUE2.X配置 ————————————————
// import Vue from 'vue'
// import Vuex from 'vuex'
//
// Vue.use(Vuex)
//
// export default new Vuex.Store({
//   state: {},
//   getters: {},
//   mutations: {},
//   actions: {},
//   modules: {}
// })

// ———————————— VUE3.X配置 ————————————————
// 参考：https://blog.csdn.net/null0112358/article/details/116305391
import { createStore } from 'vuex'
import state from './state'
import actions from './actions'
import mutations from './mutations'
import getters from './getters'

let modules = {}
try {
  const context = require.context('./modules', true, /index\.js$/)
  context.keys().forEach((key) => {
    let catalogArray = key.split('/')
    modules[catalogArray[1]] = context(key).default
  })
} catch (e) {
  throw new Error('vuex加载错误：' + e)
}

export default createStore({
  state,
  mutations,
  actions,
  getters,
  modules: {...modules}
})
